﻿using System;

namespace Haidou.Wpf.Util.Extensions
{
	/// <summary>
	/// 字符串扩展
	/// </summary>
	public static class StringExtensions
	{
		public static string Remove(this string text, params string[] keys)
		{
			if (text == null)
			{
				throw new ArgumentNullException(nameof(text), "The text should not be null.文本不应为空");
			}

			foreach (string key in keys)
			{
				text = text.Replace(key, string.Empty);
			}

			return text;
		}

		/// <summary>
		/// 缩短
		/// </summary>
		/// <param name="text"></param>
		/// <param name="size"></param>
		/// <returns></returns>
		public static string Truncate(this string text, int size)
		{
			return string.IsNullOrEmpty(text) ? string.Empty : text.Length <= size ? text : text.Substring(0, size);
		}
	}
}
